<template>
  <div class="cyber-countdown">
    <div class="time-block">
      <div class="time-number gradient-text">{{ hours }}</div>
      <div class="time-label">小时</div>
    </div>
    <div class="colon">:</div>
    <div class="time-block">
      <div class="time-number gradient-text">{{ minutes }}</div>
      <div class="time-label">分钟</div>
    </div>
    <div class="colon">:</div>
    <div class="time-block">
      <div class="time-number gradient-text">{{ seconds }}</div>
      <div class="time-label">秒数</div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, computed, onMounted, onUnmounted } from "vue";

const targetTime = ref(new Date().getTime() + 24 * 60 * 60 * 1000); // 默认24小时后
const remaining = ref(0);

const hours = computed(() =>
  Math.floor(remaining.value / 3600)
    .toString()
    .padStart(2, "0"),
);
const minutes = computed(() =>
  Math.floor((remaining.value % 3600) / 60)
    .toString()
    .padStart(2, "0"),
);
const seconds = computed(() => (remaining.value % 60).toString().padStart(2, "0"));

let timer: number | NodeJS.Timeout;

const updateTimer = () => {
  const now = new Date().getTime();
  remaining.value = Math.max(0, Math.floor((targetTime.value - now) / 1000));
};

onMounted(() => {
  timer = setInterval(updateTimer, 1000);
  updateTimer();
});

onUnmounted(() => {
  clearInterval(timer);
});
</script>

<style lang="scss" scoped>
.cyber-countdown {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: rgba(8, 8, 16, 0.9);
  border-radius: 12px;
  border: 1px solid #00f7ff;
  box-shadow: 0 0 20px rgba(0, 247, 255, 0.4);
}

.time-block {
  text-align: center;
  margin: 0 1.5rem;
}

.time-number {
  font-size: 3.5rem;
  font-family: "Monospace", sans-serif;
  letter-spacing: 2px;
  transition: all 0.3s ease;
}

.gradient-text {
  background: linear-gradient(135deg, #00f7ff 0%, #7d41ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.time-label {
  color: #00f7ff;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 0.5rem;
  text-shadow: 0 0 8px rgba(0, 247, 255, 0.6);
}

.colon {
  color: #00f7ff;
  font-size: 2.5rem;
  margin: 0 0.5rem;
  text-shadow: 0 0 10px rgba(0, 247, 255, 0.8);
}

/* 动态呼吸效果 */
@keyframes glow {
  0% {
    opacity: 0.8;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0.8;
  }
}

.cyber-countdown {
  animation: glow 2s ease-in-out infinite;
}
</style>
